<%@ page import="java.util.HashMap"%>
<%@ page import="si.sp.socialnetwork.DatabaseBean"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<%
    if (request.getParameter("username") != null &&
    		request.getParameter("username") != "" && 
    		request.getParameter("password") != null &&
    		request.getParameter("password") != "") 
    {

    	String username = request.getParameter("username");
    	String password = request.getParameter("password");
        
    	DatabaseBean db_bean = new DatabaseBean();
        boolean access_granted = db_bean.isAccessGranted(username, password);
        HashMap<String, String> sAttr = db_bean.getSessionAttributes();      
        
    	//if (username.equals("admin") && password.equals("admin")) {
        if (access_granted) {
    		
    		session.setAttribute("userID", sAttr.get("userID"));
            session.setAttribute("user", sAttr.get("user"));
    		response.sendRedirect("utrinki.jsp");
            
    	} else {
    		response.sendRedirect("index.jsp");
    	}
        
    } else {     
    	response.sendRedirect("index.jsp");
    }
%>